package cn.lkk.samples.lang.fundamental.InputAndOutput;

import java.io.Console;
import java.util.Scanner;

/**
 * Created by lkk on 2015/5/13.
 */
public class ReadingInput {
    public static void main(String[] args) {
        readPassword();
    }

    /**
     * 从控制台读取数据
     */
    public static void readFromConsole() {
        // 1.创建一个Scanner对象
        Scanner in = new Scanner(System.in);

        // 2.读取一行
        System.out.println("What is your name?");
        String name = in.nextLine();

        // 3.读取一个单词
        String firstName = in.next();

        // 4.读取一个整数
        System.out.println("How old are you?");
        int age = in.nextInt();

        System.out.printf("Hello %s. Next year, you'll be %s", firstName, age + 1);
    }

    /**
     * 使用Console对象读取密码
     */
    public static void readPassword() {
        //todo:无法获得console对象
        // 1.获取Console对象
        Console cons = System.console();
        // 2.读取密码
        char[] password = cons.readPassword("Password:");
    }
}
